import React, {FC, useCallback, useMemo} from "react";
import {coreDispatch} from "../../utils/StoreUtil.tsx";
import SelectModal from "../../component/modal/select/SelectModal.tsx";
import {useTranslation} from "react-i18next";

interface CTableFileListProps {
    menuId: string
    value: string
    data: any,
    modelProps: any,
    rowKey: string,
    width?:number,
}

const CTableFileList: FC<CTableFileListProps> = (props: any) => {
    const {t} = useTranslation()
    const handleClick: Function = useCallback(() => {
        console.log(props, "xxxxxxxx")
        const {data, rowKey = "id", menuId, modalProps = {}} = props;
        coreDispatch("modalReducer/createModal", {
            key: data[rowKey],
            modalProps: {
                title: t("fileList"),
                footer: null,
                width:600
            },
            component: SelectModal,
            comProps: {
                ...modalProps,
                menuId: menuId,
                flowData: [data]
            }
        });
    }, [props])

    const renderCTableFileList = useMemo(() => {
        const {value} = props;
        return (<div className="sf_core_preview_link">
            <span className="sf_core_preview_link_value" onClick={handleClick}
                  title={value}>{value}</span>
        </div>)
    }, [props]);
    return (renderCTableFileList)
}

export default React.memo(CTableFileList);